package com.nwpusp.model.characters;

import com.nwpusp.model.Entity;

import com.nwpusp.model.EntityClassifyManager;
import com.nwpusp.model.EntityContainer;
import com.nwpusp.model.TrackManager;
import com.nwpusp.model.barrier.Barrier;
import com.nwpusp.model.location.Axis;
import com.nwpusp.model.location.Size;
import com.nwpusp.model.location.Velocity;
import com.nwpusp.model.session.*;

import java.util.ArrayList;

public class CharacterManager extends EntityClassifyManager {
	public CharacterManager(EntityContainer globalContainer, TrackManager trackMgr) {
		super(globalContainer, trackMgr);
		GameCharacter.setTrackManager(trackMgr);
	}
	
	private static int chHeight = 2000;
	
	public boolean add(Entity e) {
		if(e instanceof GameCharacter) {
			boolean result = super.add(e);
			if(result) {
				for(int i = 0 ; i < this.size(); i++) {
					GameCharacter ch = (GameCharacter) this.get(i);
					
					ch.setSize(new Size(ch.CalcMyWidthByHeight(chHeight), 500, chHeight));
					ch.setVelocity(new Velocity(GameCharacter.noramlRunningVelocityX, 0, 0));
				}
			}
			return result;
		}
		return false;
	}
	
	public boolean remove(Entity e) {
		if(e instanceof GameCharacter) {
			return super.remove(e);
		}
		return false;
	}
	
	synchronized public void arrangeAllCharacters() {
		int startXSize = (int)(chHeight * 1.25);
		for(int i = 0 ; i < this.size(); i++) {
			GameCharacter ch = (GameCharacter) this.get(i);
			ch.setTrackNo(i);
			int startXPos = startXSize - ch.getSize().getX();
			ch.setPosition(new Axis(startXPos, trackMgr.getYByTrackNo(ch.getTrackNo()),0));
		}
	}
}